package com.yunxun.coinmessage.controller;
import com.yunxun.coinmessage.entity.PushList;
import com.yunxun.coinmessage.templatedata.MsgResult;
import com.yunxun.coinmessage.templatedata.PushListTemplateData;
import com.yunxun.coinmessage.service.PushListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class PushListController {
    @Autowired
    PushListService pushListService;

    @RequestMapping("/queryPushListModels")
    @ResponseBody
    public List<PushListTemplateData> queryPushListModels(@RequestParam("start")int start, @RequestParam("limit")int limit){
        return pushListService.queryPushListModels(start,limit);
    }
    @RequestMapping("/openPushList")
    public String openPushList(Model model){
        int total=pushListService.queryContentTotal();
        int totalPage=(total+19)/20;
        model.addAttribute("total",pushListService.queryContentTotal());
        model.addAttribute("totalPage",totalPage);
        return "push-list";
    }

    /**
     * 打开显示某篇资讯要推送用户的窗口
     * @param con_id
     * @param model
     * @return
     */
    @RequestMapping("/openQueryAllUserByConId")
    public String openQueryAllUserByConId(int con_id,Model model){
        int total=pushListService.queryTotalByConId(con_id);
        int totalPage=(total+19)/20;
        model.addAttribute("total",total);
        model.addAttribute("totalPage",totalPage);
        model.addAttribute("con_id",con_id);
        model.addAttribute("flag","all");
        return "pushlist-user";
    }

    /**
     * 打开推送成功的用户窗口
     * @param con_id
     * @param model
     * @return
     */
    @RequestMapping("/openQuerySuccessUser")
    public String openQuerySuccessUser(int con_id,Model model){
        int total=pushListService.querySuccessTotal(con_id);
        int totalPage=(total+19)/20;
        model.addAttribute("total",total);
        model.addAttribute("totalPage",totalPage);
        model.addAttribute("con_id",con_id);
        model.addAttribute("flag","success");
        return "pushlist-user";
    }

    /**
     * 打开推送失败的用户窗口
     * @param con_id
     * @param model
     * @return
     */
    @RequestMapping("/openQueryFailureUser")
    public String openQueryFailureUser(int con_id,Model model){
        int total=pushListService.queryFailureTotal(con_id);
        int totalPage=(total+19)/20;
        model.addAttribute("total",total);
        model.addAttribute("totalPage",totalPage);
        model.addAttribute("con_id",con_id);
        model.addAttribute("flag","failure");
        return "pushlist-user";
    }

    /**
     * 查询推送成功的用户
     * @param con_id
     * @param start
     * @param limit
     * @return
     */
    @RequestMapping("/querySuccessUser")
    @ResponseBody
    public List<PushList> querySuccessUser(int con_id, int start, int limit){
        return pushListService.querySuccessUser(con_id,start,limit);
    }

    /**
     * 查询推送失败的用户
     * @param con_id
     * @param start
     * @param limit
     * @return
     */
    @RequestMapping("/queryFailureUser")
    @ResponseBody
    public List<PushList> queryFailureUser(int con_id,int start,int limit){
        return pushListService.queryFailureUser(con_id,start,limit);
    }
    /**
     * 查询谋篇资讯要推送的所有用户
     * @param con_id
     * @param start
     * @param limit
     * @return
     */
    @RequestMapping("/queryAllUserByConId")
    @ResponseBody
    public List<PushList> queryAllUserByConId(int con_id,int start,int limit){
        return pushListService.queryAllUserByConId(con_id,start,limit);
    }
    @RequestMapping("/pushTop")
    @ResponseBody
    public MsgResult pushTop(int con_id){
        return pushListService.pushTop(con_id);
    }
    @RequestMapping("/pushTopByUser")
    @ResponseBody
    public MsgResult pushTop(int con_id,int uid){
        return pushListService.pushTopByUser(con_id,uid);
    }

}
